package com.ruoyi.project.member.aicoinpackage.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.member.aicoinpackage.domain.AicoinPackage;
import com.ruoyi.project.member.aicoinpackage.service.IAicoinPackageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * AI币套餐Controller
 * 
 * @author shixiangwen
 * @date 2023-06-13
 */
@Controller
@RequestMapping("/member/aicoinpackage")
public class AicoinPackageController extends BaseController
{
    private String prefix = "member/aicoinpackage";

    @Autowired
    private IAicoinPackageService aicoinPackageService;

    @RequiresPermissions("member:aicoinpackage:view")
    @GetMapping()
    public String aicoinpackage()
    {
        return prefix + "/aicoinpackage";
    }

    /**
     * 查询AI币套餐列表
     */
    @RequiresPermissions("member:aicoinpackage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AicoinPackage aicoinPackage)
    {
        startPage();
        List<AicoinPackage> list = aicoinPackageService.selectAicoinPackageList(aicoinPackage);
        return getDataTable(list);
    }

    /**
     * 导出AI币套餐列表
     */
    @RequiresPermissions("member:aicoinpackage:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AicoinPackage aicoinPackage)
    {
        List<AicoinPackage> list = aicoinPackageService.selectAicoinPackageList(aicoinPackage);
        ExcelUtil<AicoinPackage> util = new ExcelUtil<AicoinPackage>(AicoinPackage.class);
        return util.exportExcel(list, "aicoinpackage");
    }

    /**
     * 新增AI币套餐
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存AI币套餐
     */
    @RequiresPermissions("member:aicoinpackage:add")
    @Log(title = "AI币套餐", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AicoinPackage aicoinPackage)
    {
        return toAjax(aicoinPackageService.insertAicoinPackage(aicoinPackage));
    }

    /**
     * 修改AI币套餐
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AicoinPackage aicoinPackage = aicoinPackageService.selectAicoinPackageById(id);
        mmap.put("aicoinPackage", aicoinPackage);
        return prefix + "/edit";
    }

    /**
     * 修改保存AI币套餐
     */
    @RequiresPermissions("member:aicoinpackage:edit")
    @Log(title = "AI币套餐", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AicoinPackage aicoinPackage)
    {
        return toAjax(aicoinPackageService.updateAicoinPackage(aicoinPackage));
    }

    /**
     * 删除AI币套餐
     */
    @RequiresPermissions("member:aicoinpackage:remove")
    @Log(title = "AI币套餐", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(aicoinPackageService.deleteAicoinPackageByIds(ids));
    }
}
